package cn.stylefeng.guns.modular.rw.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.core.ParamUtil;
import cn.stylefeng.guns.modular.rw.entity.BrankBannerThree;
import cn.stylefeng.guns.modular.rw.service.IBrankBannerThreeService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 描述：品牌理念区块三表 controller
 * 作者：chenhuiyan
 * 时间：2020-05-07
 */
@Controller
@RequestMapping("/rw/brankBannerThree")
public class BrankBannerThreeController extends BaseController {

    private String PREFIX = "/modular/rw/brankBannerThree/";

    @Autowired
    private IBrankBannerThreeService brankBannerThreeService;

    /**
     * 跳转到管理首页
     */
    @RequestMapping(value = "")
    public String index() {
        return PREFIX + "brankBannerThree.html";
    }

    /**
     * 获取列表
     */
    @ResponseBody
    @RequestMapping(value = "/list")
    public Object list() {
        Map<String, Object> params = ParamUtil.getParams();
        Page<Map<String, Object>> list = brankBannerThreeService.list(params);
        return LayuiPageFactory.createPageInfo(list);
    }

    /**
     * 跳转添加/修改页面
     * @param model
     * @param brankBannerThreeId
     * @return
     */
    @RequestMapping(value = "/addOrEdit")
    public String addOrEdit(Model model, String brankBannerThreeId) {
        model.addAttribute("brankBannerThreeId", brankBannerThreeId);
        return PREFIX + "brankBannerThree_add.html";
    }

    /**
     * 保存
     * @param brankBannerThree
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/save")
    public ResponseData save(BrankBannerThree brankBannerThree) {
        if (ToolUtil.isEmpty(brankBannerThree.getId())) {
            brankBannerThree.preInsert();
            brankBannerThreeService.save(brankBannerThree);
        }else{
            brankBannerThree.preUpdate();
            brankBannerThreeService.updateById(brankBannerThree);
        }
        return SUCCESS_TIP;
    }

    /**
     * 获取详情
     * @param brankBannerThreeId
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getInfoById/{brankBannerThreeId}")
    public Object getInfoById(@PathVariable("brankBannerThreeId") String brankBannerThreeId){
        Map<String, Object> res = brankBannerThreeService.getInfoById(brankBannerThreeId);
        return res;
    }

}
